#!/usr/bin/env bash
set -ex

# cni flag
kubectl -n kube-public delete cm cni-calico

kubectl -n kube-system delete cm calico-config

# calico crd
kubectl delete crd felixconfigurations.crd.projectcalico.org
kubectl delete crd ipamblocks.crd.projectcalico.org
kubectl delete crd blockaffinities.crd.projectcalico.org
kubectl delete crd ipamhandles.crd.projectcalico.org
kubectl delete crd ipamconfigs.crd.projectcalico.org
kubectl delete crd bgppeers.crd.projectcalico.org
kubectl delete crd bgpconfigurations.crd.projectcalico.org
kubectl delete crd ippools.crd.projectcalico.org
kubectl delete crd hostendpoints.crd.projectcalico.org
kubectl delete crd clusterinformations.crd.projectcalico.org
kubectl delete crd globalnetworkpolicies.crd.projectcalico.org
kubectl delete crd globalnetworksets.crd.projectcalico.org
kubectl delete crd networkpolicies.crd.projectcalico.org
kubectl delete crd networksets.crd.projectcalico.org

# delete calico tunnel
for pod in calico-node-b5t8f
do
  kubectl exec -n kube-system "" -- modprobe -r ipip
done

# calico-node
kubectl -n kube-system delete ds calico-node
kubectl -n kube-system delete sa calico-node
kubectl delete clusterrole calico-node
kubectl delete clusterrolebinding calico-node

# calico-kube-controllers
kubectl -n kube-system delete deploy calico-kube-controllers
kubectl -n kube-system delete sa calico-kube-controllers
kubectl delete clusterrole calico-kube-controllers
kubectl delete clusterrolebinding calico-kube-controllers
